let arr = JSON.parse(localStorage.getItem('examResult'))
let tbody = document.querySelector('tbody')
function XR() {
  // 获取本地数据
  let i = 0
  for (mes of arr) {
    tbody.innerHTML = ''
    let tr = document.createElement('tr')
    tr.innerHTML = `
     <tr>
        <td>${mes.examID}</td>
        <td>${mes.user}</td>
        <td>${mes.scores}</td>
        <td>${mes.grade}</td>
        <td>
         <button class="del" data-id="${i}">删除</button>
        <button class="anew" data-id="${i}">重考</button>
        </td>
      </tr>
    `
    tbody.appendChild(tr)
    i++
  }
}
XR()
tbody.addEventListener('click', function (e) {
  // 删除
  if (e.target.className == 'del') {
    if (confirm('确定删除考试成绩吗？')) {
      arr.splice(e.target.dataset.id, 1)
      localStorage.setItem('examResult', JSON.stringify(arr))
      examXR()
    }
  }
  XR()
})
